<template>
  <div class="bookshelf">
    <div class="title">
      <div class="text">
        橙子小说
        <i class="iconfont icon-chengzi"></i>
      </div>
      <div class="story">
        <i
          class="iconfont icon-lishijilu"
          @click="$router.push('/history')"
        ></i>
        <i class="iconfont icon-sousuo" @click="$router.push('/search')"></i>
        <i class="iconfont icon-liebiaoxuanze-" v-show="flag" @click="set"></i>
        <i
          class="wancheng iconfont icon-xuanzhong"
          v-show="!flag"
          @click="reset"
        ></i>
      </div>
    </div>
    <div class="bookshelfContent">
      <div class="banner">
        <img :src="banner.img" />
      </div>

      <ul>
        <li v-for="(item, index) in shelf" :key="item.id">
          <div class="img">
            <img :src="item.img" />
          </div>
          <h1
            @click="$router.push({ name: 'synopsis', query: { id: item.id } })"
          >
            {{ item.title }}
          </h1>
          <p>{{ item.number }} | {{ item.end }}</p>
          <div class="mask" v-show="!flag">
            <i class="iconfont icon-lajitong" @click="del(index)"></i>
          </div>
        </li>

        <li @click="$router.push('/index')">
          <div class="bigAdd">+</div>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import { getShelfImg, getShelf } from "../api/index";
export default {
  data() {
    return {
      flag: true,
      active: "bookshelf",
      banner: [],
      shelf: [],
    };
  },
  methods: {
    set() {
      this.flag = false;
    },
    reset() {
      this.flag = true;
    },
    del(index) {
      this.shelf.splice(index, 1);
      console.log(this.shelf);
    },
  },
  created() {
    getShelfImg().then((data) => {
      this.banner = data;
      // console.log(data);
    });
    getShelf().then((data) => {
      this.shelf = data.shelf;
      let newShelf = JSON.parse(localStorage.getItem("shelf"));
      // console.log(newShelf);
      newShelf.forEach((item) => {
        // console.log(item);
        this.shelf.unshift(item);
      });
    });
  },
};
</script>

<style lang="less">
.bookshelf {
  .title {
    position: fixed;
    width: 100%;
    min-height: 50px;
    display: flex;
    align-items: baseline;
    background-color: #fff;
    z-index: 1;
    padding: 0 15px;
    box-sizing: border-box;
    .text {
      flex: 1;
      line-height: 50px;
      font-size: 20px;
      i {
        font-size: 22px;
        color: orange;
      }
    }
    .story {
      i {
        margin-left: 20px;
        text-align: center;
        line-height: 50px;
        font-size: 26px;
      }
      .wancheng {
        color: rgb(35, 179, 130);
      }
    }
  }
  .bookshelfContent {
    padding: 15px;
    padding-top: 50px;
    background-color: #fff;
    border-radius: 6px;
    .banner {
      position: fixed;
      top: 47px;
      width: 92%;
      height: 60px;
      background-color: #fff;
      z-index: 1;
      img {
        width: 100%;
        height: 60px;
      }
    }
    ul {
      margin-top: 57px;
      margin-bottom: 60px;
      display: flex;
      flex-wrap: wrap;
      padding-top: 10px;
      li {
        margin-bottom: 10px;
        margin-right: 10.5px;
        margin-left: 10.5px;
        position: relative;
        .img {
          img {
            width: 100px;
            height: 140px;
          }
        }
        h1 {
          width: 100px;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
          padding-top: 6px;
        }
        p {
          font-size: 12px;
          padding-top: 6px;
          color: #999;
        }
        .mask {
          position: absolute;
          top: 0;
          left: 0;
          width: 100px;
          height: 140px;
          background-color: rgba(255, 255, 255, 0.5);
          i {
            font-size: 20px;
            padding-left: 77px;
          }
        }

        .bigAdd {
          width: 100px;
          height: 140px;
          border: 1px solid #f6f7f9;
          text-align: center;
          font-size: 50px;
          line-height: 140px;
          color: #f6f7f9;
        }
      }
    }
    :first-child,
    :nth-child(3n + 1) {
      margin-left: 0;
    }
    :nth-child(3n) {
      margin-right: 0;
    }
  }
}
</style>